//ui.h

#ifndef UI_H_INCLUDED
#define UI_H_INCLUDED
using namespace std;

#include <freeglut.h> 
#include "gamedrawer.h"
#include "game.h"
#include "world.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>

class Game;
class CommandButton;

//abstract parent of other UI elements
class UIElement{
	public:
		int x;
		int y;
		int width;
		int height;
		void update();
		void draw();
		UI * owner;	
};

class Menu: public UIElement{
	public:
	Menu();
	void draw();
	private:
	Color menuColors[4];
};

/* A table holding the list of structures 
 * that can be built.
 */
class StructureTable: public UIElement{
	public:
		StructureTable(UI * owner,int,int);
		void draw();
		void update();
		void setSelection(string selectedType);
		void select();
		bool collide(int x, int y);
		string getSelected();
		int getSelectedSize();
	private:
		string selection;
		vector<CommandButton*> structureList;
};

class CommandButton: public UIElement{
	public:
		CommandButton(UI * ownerIn, string typeIn){
			x = 0;
			y = 0;
			width = 50;
			height = 50;
			structureType = typeIn;
			offset = 3;
			cell_size = 50;
			owner = ownerIn;
		}
		void draw(int xIn, int yIn);
		void update();
		bool hover();
		string structureType;
	private:
		float offset;
		float cell_size;

};

/* 
 * A table displaying the list of abilities 
 * of the currently-selected object(s).
 */
class AbilitiesTable: public UIElement{};

/*
 *	Tracks and displays the player's total 
 *	resource count.
 */
class ResourceDisplay: public UIElement{};

/* 
 * Manages drag-select functionality.
 */
class SelectionBox: public UIElement{
public:
	SelectionBox(){
		active = false;
	}
	void newSelection(Coord newStart);
	void updateSelection(Coord newEnd);
	void endSelection();
	void draw();
	bool active;
	Coord start;
	Coord end;
	Coord tempStart;
};

/*
 * The UI draws relevant information to the screen,
 * assists in issuing commands to the game.
 */
class UI{
	private:
		Menu* menu;		
		SelectionBox sbox;

	public:
		UI(int, int);
		Game* game;
		StructureTable * structureTable;
		void handleMouseInput();
		void mouseDragged();
		int mouseX;
		int mouseY;
		void update();
		void draw();
};

#endif
